/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Ejercicio9_5_1;

/**
 *
 * @author alumno
 */
public class DateThree {
    private int day = 0;
    private int month = 0;
    private int year = 0;
    private boolean dateIsValid = false;

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        if (month > 12) {
            System.out.println("Error, el mes no puede ser mayor a 12!");
        }
        else  {
            this.month = month;
        }
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int calcDaysInMonth( int  month ) {
        switch (month) {

            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                return 31;
            case 2:
                return 28;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
            default:
                return -1;

        }

    }
   public void setDate(int month, int day, int year) {
       int daysInMonth = 0;

       daysInMonth = this.calcDaysInMonth(month);

       if (daysInMonth < 0) {
           this.dateIsValid = false;
           System.out.println("Error! el mes no existe");
       }

       this.month = month;

       if (day > daysInMonth) {
           this.dateIsValid = false;
           System.out.println("Error! el mes " + month + " tiene " + daysInMonth + " dias" );
       }
       else {
           this.setDay(day);
           this.setYear(year);
           this.dateIsValid = true;
       }

     

   }

   public void displayDate() {

       if ( this.dateIsValid ) {
            System.out.println(this.month + "/" + this.day + "/" + this.year);
       }
   }
}
